package com.hj.aimin.auth.Service;

import com.alibaba.fastjson2.JSONObject;
import com.hj.aimin.auth.pojo.Jscode2sessionResult;
import com.hj.aimin.auth.properties.WXProperties;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
@RequiredArgsConstructor
public class WxService {

    private final RestTemplate  restTemplate ;

    private final WXProperties wxProperties ;
    public Jscode2sessionResult wxLogin(String code) {
        String url = "https://api.weixin.qq.com/sns/jscode2session?appid="
                + wxProperties.getAppId() + "&secret="
                + wxProperties.getSecret() + "&js_code="
                + code + "&grant_type=authorization_code";
        System.out.println(wxProperties.getAppId()+""+wxProperties.getSecret());
        return JSONObject.parseObject(restTemplate.getForObject(url, String.class), Jscode2sessionResult.class);
    }
}
